package com.github.kezhenxu94.playground.java.interview.didi;

import java.util.Scanner;

public class DDTransform {

	private static char[] digits = "0123456789ABCDEF".toCharArray();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		if (m == 0) {
			System.out.println(0);
		} else {
			StringBuilder sb = new StringBuilder();
			boolean lessThan0 = m < 0;
			if (m < 0)
				m = -m;
			while (m > 0) {
				sb.insert(0, digits[m % n]);
				m /= n;
			}
			if (lessThan0)
				sb.insert(0, '-');
			System.out.println(sb.toString());
		}
		sc.close();
	}
}
